package com.wudimeng.syll.controller.api;


import com.wudimeng.syll.common.ApiResponse;
import com.wudimeng.syll.constants.Constant;
import com.wudimeng.syll.entity.CChuKuXinXiWeiTuo;
import com.wudimeng.syll.service.ICChuKuXinXiWeiTuoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author laohei
 * @Date 2020/6/8 9:50
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("syll")
public class CChuKuXinXiWeiTuoController {

    @Autowired
    private ICChuKuXinXiWeiTuoService service;

    @GetMapping("/ChuKuXinXiWeiTuo")
    public ApiResponse getChuKuXinXiWeiTuo(HttpServletRequest  request){
        try {
            Map<String,String> map = new HashMap<>();
            map.put("startDate",request.getParameter("startDate"));
            map.put("endDate",request.getParameter("endDate"));
            map.put("ChanPinMingCheng",request.getParameter("ChanPinMingCheng"));
            map.put("LengKu",request.getParameter("LengKu"));
            map.put("GuoChanHuoJinKouChuKu",request.getParameter("GuoChanHuoJinKouChuKu"));
            map.put("YongHuID",request.getParameter("YongHuID"));
            map.put("WeiTuoID",request.getParameter("WeiTuoID"));
            Integer pageNum = Integer.valueOf(request.getParameter("pageNum"));
            Integer pageSize = Integer.valueOf(request.getParameter("pageSize"));
            return this.service.selectCChuKuXinXiWeiTuo(map,pageNum,pageSize);
        } catch (Exception e) {
            log.error("ChuKuXinXiWeiTuo.getChuKuXinXiWeiTuo.请稍后再试:" + e.getMessage());
            return ApiResponse.error(Constant.COMMON_PARAMETER_DEGRADE);
        }
    }

    @GetMapping("/ChuKuXinXiWeiTuoById")
    public ApiResponse getChuKuXinXiWeiTuoById(HttpServletRequest  request){
        try {
            String id = request.getParameter("id");
            return this.service.selectCChuKuXinXiWeiTuoById(Integer.valueOf(id));
        } catch (Exception e) {
            log.error("ChuKuXinXiWeiTuo.getChuKuXinXiWeiTuoById.请稍后再试:" + e.getMessage());
            return ApiResponse.error(Constant.COMMON_PARAMETER_DEGRADE);
        }
    }

    @PostMapping("/ChuKuXinXiWeiTuo")
    public ApiResponse addChuKuXinXiWeiTuo(@RequestBody CChuKuXinXiWeiTuo chuKuXinXiWeiTuo, HttpServletRequest request){
        return service.addCChuKuXinXiWeiTuo(chuKuXinXiWeiTuo);
    }

    @PutMapping("/ChuKuXinXiWeiTuo")
    public ApiResponse updChuKuXinXiWeiTuo(@RequestBody CChuKuXinXiWeiTuo chuKuXinXiWeiTuo, HttpServletRequest request){
        try {
            service.updCChuKuXinXiWeiTuo(chuKuXinXiWeiTuo);
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResponse.error(Constant.COMMON_UPDATE_FAIL);
        }
        return ApiResponse.success(Constant.COMMON_UPDATE_SUCCESS);
    }
}
